package com.xingyun.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.xingyun.app.data.api.service.ApiService;
import com.xingyun.app.data.entity.TodayArticleResponse;
import com.xingyun.mvp.contract.MainPagerContract;

import javax.inject.Inject;

import io.reactivex.Observable;


@ActivityScope
public class MainPagerModel extends BaseModel implements MainPagerContract.Model {
    private Gson mGson;
    private Application mApplication;

    @Inject
    public MainPagerModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<TodayArticleResponse> getArticle(String data) {
        return mRepositoryManager
                .obtainRetrofitService(ApiService.class)
                .getArticle(data);

//        return Observable.just(mRepositoryManager
//                .obtainRetrofitService(ApiService.class)
//                .getArticle(data)
//                .flatMap(new Function<Observable<TodayArticleResponse>, ObservableSource<TodayArticleResponse>>() {
//                    @Override
//                    public ObservableSource<TodayArticleResponse> apply(Observable<TodayArticleResponse> todayArticleResponseObservable) throws Exception {
//                        return mRepositoryManager.obtainCacheService();
//                    }
//                })
//        );
    }
}